//
//  GuangdetaController.m
//  Shopping
//
//  Created by qianfeng on 16/1/15.
//  Copyright © 2016年 qianfeng. All rights reserved.
//

#import "GuangdetaController.h"

#import "MyNavigationBar.h"
#import "MyNavitaionItem.h"

#import "GuangAllModle.h"

#import "GuangDetaViewCell.h"

#import "UMSocial.h"

@interface GuangdetaController ()<UITableViewDataSource,UITableViewDelegate,UMSocialUIDelegate>
/**  展示界面  */
@property(strong , nonatomic) UITableView * mainTableView;
/**
 *  存放数据
 */
@property(strong , nonatomic) NSMutableArray * mainDataSource;
/** 获取全局tabbar */
@property(nonatomic,strong) MyNavigationBar * bar;

@property(strong , nonatomic) UIView * toolView;

@end

@implementation GuangdetaController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    [self loadMyNavigationBar];
    [self.view addSubview:self.mainTableView];
    
    
    _toolView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.mainTableView.frame), BoundsWidth, 35)];
    
    _toolView.backgroundColor = [UIColor blackColor];
    
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 35)];
    label.text = [NSString stringWithFormat:@"¥ %d",self.model.secooPrice.intValue];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:12];
    label.backgroundColor = [UIColor grayColor];
    label.textColor = [UIColor redColor];
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(100, 0, BoundsWidth - 100, 35);
    [button setTitle:@"去购买" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:11];
    [button setImage:[UIImage imageNamed:@"shop_nav"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(btnShoppingClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.toolView addSubview:button];
    [self.toolView addSubview:label];
    
    [self.view addSubview:_toolView];

    
}
/** 加载导航 */
-(void)loadMyNavigationBar
{
    MyNavitaionItem *leftItem = [[MyNavitaionItem alloc] init];
    leftItem.itemImageName = @"back";
    
    MyNavitaionItem * rightItem = [[MyNavitaionItem alloc] init];
    rightItem.itemImageName = @"share";
    
    self.bar = [self createMyNavigationBarWithBgImageName:nil andTitle:@"商品详情" andTitleView:nil andLeftItems:@[leftItem] andRightItems:@[rightItem] andSEL:@selector(backHomePage:) andClass:self];
}
/** 返回按钮的返回事件 */
-(void)backHomePage:(UIButton *)btn
{
    if(btn.tag == 1000)
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
    else
    {
        [UMSocialSnsService presentSnsIconSheetView:self appKey:@"569a3fad67e58e64e6002822" shareText:@"分享成功" shareImage:[UIImage imageNamed:@"icon.png"] shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToSms,UMShareToWechatSession,UMShareToWechatTimeline,UMShareToQQ, nil] delegate:self];

    }
}
#pragma mark -------懒加载----------
-(UITableView *)mainTableView
{
    if (_mainTableView == nil) {
        _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, BoundsWidth, BoundsHeight - 64 - 35) style:UITableViewStylePlain];
        _mainTableView.delegate = self;
        _mainTableView.dataSource = self;
        _mainTableView.rowHeight = 600;
        _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainTableView.tableFooterView = self.toolView;
        _mainTableView.backgroundColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1];
         [_mainTableView registerNib:[UINib nibWithNibName:@"GuangDetaViewCell" bundle:nil] forCellReuseIdentifier:@"DetaCell"];
    }
    return _mainTableView;
}

-(NSMutableArray *)mainDataSource
{
    if (_mainDataSource == nil) {
        _mainDataSource =[[NSMutableArray alloc]init];
    }
    return _mainDataSource;
}
#pragma mark -- 显示和隐藏tabBar
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.tabBarController.tabBar.hidden = NO;
}


#pragma mark ------ 协议方法------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    GuangDetaViewCell * cell = [GuangDetaViewCell cellWithTableView:tableView];
    cell.model = self.model;
    
    return cell;
}


-(void)btnShoppingClick:(UIButton *)btn
{
    DJLog(@"去购买");
}
@end
